﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Caching;

namespace DemoApp1.Common
{
    public class CacheHelper
    {
        static CacheHelper instance;
        public static CacheHelper Instance
        {
            get
            {
                if (instance == null)
                {
                    instance = new CacheHelper();
                }

                return instance;
            }
        }


        public object Get(string key)
        {
            Cache cache = HttpRuntime.Cache;
            return cache[key];
        }

        public void Set(string key, object obj)
        {
            Cache cache = HttpRuntime.Cache;
            if (obj != null)
            {
                cache.Insert(key, obj);
            }
        }

        public void Set(string key, object obj, TimeSpan tspan)
        {
            Cache cache = HttpRuntime.Cache;
            if (obj != null)
            {
                cache.Insert(key, obj, null, Cache.NoAbsoluteExpiration, tspan);
            }
        }

        public void Remove(string key)
        {
            Cache cache = HttpRuntime.Cache;
            if (cache[key] != null)
            {
                cache.Remove(key);
            }
        }
    }
}